package com.jixiang.goods.controller;



import com.baomidou.mybatisplus.extension.api.ApiController;
import com.jixiang.goods.service.*;
import com.jixiang.model.common.dtos.ResponseResult;
import com.jixiang.model.goods.dtos.CartDtos;
import com.jixiang.model.goods.dtos.GoodsAddDtos;
import com.jixiang.model.goods.dtos.GoodsDto;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * (GsGoodsInfo)表控制层
 *
 * @author makejava
 * @since 2023-10-23 20:55:53
 */
@RestController
@RequestMapping("goodsInfo")
public class GsGoodsInfoController extends ApiController {
    /**
     * 服务对象
     */
    @Resource
    private GsGoodsInfoService gsGoodsInfoService;



    @ApiOperation("管理端添加商品")
    @PostMapping("/adminAddGoods")
    public ResponseResult adminAddGoods(@RequestBody(required = true) GoodsAddDtos goodsDtos){
        return gsGoodsInfoService.adminAddGoods(goodsDtos);
    }


    @ApiOperation("管理端获取商品")
    @GetMapping("/adminGetGoodsList")
    public ResponseResult adminGetGoodsList(@RequestParam(required = false,defaultValue = "1",value = "pageNum")int pageNum,
                                            @RequestParam(required = false,defaultValue = "10",value = "pageSize")int pageSize,
                                            @RequestParam(required = false,value = "goodsSelect")String goodsSelect,
                                            @RequestParam(required = false,value = "goodsState")String goodsState,
                                            @RequestParam(required = false,value = "goodsName")String goodsName){
        return gsGoodsInfoService.adminGetGoodsList(pageNum,pageSize,goodsSelect,goodsState,goodsName);
    }

    @ApiOperation("用户端端获取new商品")
    @GetMapping("/appGetGoodsListByNew")
    public ResponseResult appGetGoodsListByNew(){
        return gsGoodsInfoService.appGetGoodsListByNew();
    }

    @ApiOperation("用户端端获取hot商品")
    @GetMapping("/appGetGoodsListByHot")
    public ResponseResult appGetGoodsListByHot(){
        return gsGoodsInfoService.appGetGoodsListByHot();
    }

    @ApiOperation("创建es的索引")
    @PostMapping("/addGoodsIndex")
    public ResponseResult addGoodsIndex(){
        return gsGoodsInfoService.addGoodsIndex();
    }

    @ApiOperation("跟新es的索引good数据")
    @PostMapping("/updateGoodsSearch")
    public ResponseResult updateGoodsSearch(){
        return gsGoodsInfoService.updateGoodsSearch();
    }

    @ApiOperation("跟新redis的id獲取good数据")
    @GetMapping("/appGetGoodsInfoById")
    public ResponseResult appGetGoodsInfoById(@RequestParam(required = true,value = "id")String id){
        return gsGoodsInfoService.appGetGoodsInfoById(id);
    }

    @ApiOperation("跟新redis的id獲取good数据")
    @GetMapping("/getGoodsInfoById")
    public GoodsDto getGoodsInfoById(@RequestParam(required = true,value = "id")String id){
        return gsGoodsInfoService.getGoodsInfoById(id);
    }

    @ApiOperation("跟新商品和商品选择返回相同类型数据")
    @GetMapping("/appGetGoodsHotByGoodsId")
    public ResponseResult appGetGoodsHotByGoodsId(@RequestParam(required = true,value = "id")String id,@RequestParam(required = true,value = "type")String type){
        return gsGoodsInfoService.appGetGoodsHotByGoodsId(id,type);
    }

    @ApiOperation("wx用户端端获取hot商品")
    @GetMapping("/wxGetGoodsListByHot")
    public ResponseResult wxGetGoodsListByHot(){
        return gsGoodsInfoService.wxGetGoodsListByHot();
    }

    @ApiOperation("wx用户端端获取hot商品通过selectId")
    @GetMapping("/wxGetGoodsListBySelectId")
    public ResponseResult wxGetGoodsListBySelectId(@RequestParam(required = false,value = "pageSize")int pageSize,
                                                   @RequestParam(required = false,value = "pageNum")int pageNum,
                                                   @RequestParam(required = false,value = "selectId")int selectId){
        return gsGoodsInfoService.wxGetGoodsListBySelectId(pageNum,pageSize,selectId);
    }

//    @ApiOperation("用于微服务判断库存")
//    @GetMapping(value = "/goodsInventory",produces = MediaType.APPLICATION_JSON_VALUE)
//    public String goodsInventory(@RequestBody(required = true)List<CartDtos> cartDtosList){
//        return gsGoodsInfoService.goodsInventory(cartDtosList);
//    }
}

